<template>
  <el-dialog
    append-to-body
    :title="title"
    :visible.sync="dialogFormVisible"
    width="500px"
    @close="close"
  >
    <el-form ref="form" :model="form">
      <el-form-item>
        <el-input
          v-model="form.field_value"
          placeholder="请填写备注信息"
          :rows="5"
          type="textarea"
        />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { editOwnerInfo } from '@/api/owner'

  export default {
    name: 'OwnerDesc',
    data() {
      return {
        form: {
          owner_id: '',
          field_name: 'owner_remark',
          field_value: '',
        },
        title: '编辑备注信息',
        dialogFormVisible: false,
      }
    },
    methods: {
      showEdit(e) {
        this.form.owner_id = e.id
        this.form.field_value = e.owner_remark
        this.dialogFormVisible = true
      },
      close() {
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      save() {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.edit()
          }
        })
      },
      async edit() {
        const { data } = await editOwnerInfo(this.form)
        if (data.is_success) {
          this.$baseMessage('修改成功', 'success', 'vab-hey-message-success')
          this.$emit('fetch-data')
          this.close()
        }
      },
    },
  }
</script>
